package daos

import (
	"gorm.io/gorm"
	"water-temperature-server/config"
	"water-temperature-server/dao"
)

var daoConnectMap = make(map[string]dao.DaoConfig, 0)

type Daos struct {
	Name string
}

func (e *Daos) GetDB(key string) *gorm.DB {
	data := daoConnectMap[key]
	return dao.GetDB(&data)
}

func OpenConnect() {
	databases := *config.Connects
	for key, value := range databases {
		itemDao := dao.CreateDao(value)
		var daoConnectConfig dao.DaoConfig
		daoConnectConfig.Config = value
		daoConnectConfig.Dao = itemDao
		daoConnectMap[key] = daoConnectConfig
	}
}
